#ifndef basePositionhpp
#define basePositionhpp

#include "common.hpp"
#include "conicPath.hpp"
#include "orbits.hpp"

class starSystem;

/* Base class for a physical object that can have a position in a star system. */
class basePosition
{
protected:
	static int pglobalID;
//	std::vector< std::shared_ptr<basePosition> > pList;
	std::weak_ptr<basePosition> pParent;
	std::weak_ptr<starSystem> pSystem;
	stvec state;             // state vector, relative to parent
	stvec oldState;          // relative old state vector
	unsigned char moveType;  // flag for movement type, 0 indicates stationary
	double pMu;              // standard gravitational parameter
	double pRadius;
	double SOI;
	sf::CircleShape renderSOI;
	sf::VertexArray renderVel;
	sf::VertexArray renderMove;

public:
	sf::CircleShape renderBody;
	int plocalID;
	std::weak_ptr<basePosition> self;

	basePosition();

	void virtual tick(int64_t timeStep);

	void virtual refreshDisp();

	void virtual draw(sf::RenderWindow * window);

//	void addChild( std::shared_ptr<basePosition> childPtr);

	/* Returns projected position/velocity at globTime = t */
	virtual stvec getTState(int64_t t);
	virtual stvec getTStateAbs(int64_t);

	void flushState();

//	bool hasTicked();

//	void resetTicked();

	stvec  getState();
	stvec  getStateAbs();
	void   setState(double inpx, double inpy, double invx, double invy);
	virtual void setState(stvec instate);
	double getPosX();
	void   setPosX(double inpx);
	double getPosY();
	void   setPosY(double inpy);
	double getVelX();
	void   setVelX(double invx);
	double getVelY();
	void   setVelY(double invy);
	stvec  getOldState();

	virtual char getMove();

	double getMu();
	void   setMu(double inmu);

	double getRad();
	void   setRad(double inrad);

	double getSOI();
	void   setSOI(double insoi);

	std::weak_ptr<basePosition> getParent();
	virtual void setParentw(std::weak_ptr<basePosition>   inparent);
	virtual void setParents(std::shared_ptr<basePosition> inparent);
//	virtual void setParent( basePosition * inparent );

	std::weak_ptr<starSystem> getSys();
	void setSys(std::weak_ptr<starSystem> insys);
};

#endif // basePositionhpp
